package com.yezong.AidMe.controller;

import com.yezong.AidMe.service.AddressLngLatExchange;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


@RequestMapping("address")
@Controller
public class AddressController {

    @Autowired
    AddressLngLatExchange addressLngLatExchange;

    @RequestMapping("/getAddress")
    @ResponseBody
    public String getAddress(HttpServletRequest request){
        String ip=request.getRemoteAddr();
        String address=addressLngLatExchange.getAddress(ip);

        System.out.println("ip:"+ip+" res:"+address);
        return address;
    }

    @RequestMapping("/getdis")
    @ResponseBody
    public double getDis(String begin, String end){
        System.out.println("begin:"+begin+"  end:"+end);
        double dis=addressLngLatExchange.toCalDis(begin,end);

        System.out.println("dis:"+dis);
        return dis;
    }

    @RequestMapping("/getLngLat")
    @ResponseBody
    public String getLngLat(String address){
        String lngLat=addressLngLatExchange.getLngLat(address);

        System.out.println("lngLat:"+lngLat);
        return lngLat;
    }
}
